/**
 * @file       st7789.h
 * @author     wangbing
 * @email      mz8023yt@163.com
 * @version    V1.0
 * @date       2022-03-08
 * @brief      ips lcd panel drvier
 */

#ifndef _ST7789_H_
#define _ST7789_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

#define LOW 0
#define HIGH 1

#define RGB565_WHITE 0xFFFF
#define RGB565_BLACK 0x0000
#define RGB565_BLUE 0x001F
#define RGB565_BRED 0XF81F
#define RGB565_GRED 0XFFE0
#define RGB565_GBLUE 0X07FF
#define RGB565_RED 0xF800
#define RGB565_MAGENTA 0xF81F
#define RGB565_GREEN 0x07E0
#define RGB565_CYAN 0x7FFF
#define RGB565_YELLOW 0xFFE0
#define RGB565_BROWN 0XBC40
#define RGB565_BRRED 0XFC07
#define RGB565_GRAY 0X8430

/**
 * @brief ST7789
 */
struct st7789 {
        struct {
                struct {
                        int (*read)(uint8_t* bytes, uint32_t len);
                        void (*write)(uint8_t* bytes, uint32_t len);
                } spi;
                struct {
                        void (*msleep)(int ms);
                } time;
                struct {
                        void (*rst)(int val);
                        void (*bl)(int val);
                        void (*cs)(int val);
                        void (*clk)(int val);
                        void (*mo)(int val);
                } pin;
        } ops;
        struct {
                struct {
                        int width;
                        int height;
                        int xoffset;
                        int yoffset;
                } fix;
                struct {
                        int orien;
                } var;
        } param;
};

void st7789_init(struct st7789* lcd);
void st7789_area_set(struct st7789* lcd, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void st7789_point_draw(struct st7789* lcd, uint16_t x, uint16_t y, uint16_t color);
void st7789_rect_fill(struct st7789* lcd, uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color);
void st7789_screen_fill(struct st7789* lcd, uint16_t color);

#ifdef __cplusplus
}
#endif

#endif
